﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="DelegateThreadDebugger.cs" company="JDML Consulting Ltd.">
//   Copyright 2011 Photon Project - http://photon.codeplex.com
// </copyright>
// <summary>
//   Defines the DelegateThreadDebugger type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Photon.Testing.Threading
{
    using System;

    public static class DelegateThreadDebugger
    {
        private static void BeforeInvoke(string actionName)
        {
            System.Diagnostics.Debug.WriteLine(String.Format("Executing \'{0}\', Thread properties: {{{1}}}.",
               actionName ?? String.Empty, TestThreadInfo.FromCurrentThread()));
        }

        public static Func<T> Debug<T>(string name, Func<T> func)
        {
            return () =>
                      {
                          BeforeInvoke(name);
                          return func();
                      };
        }

        public static Func<T, TReturn> Debug<T, TReturn>(string name, Func<T, TReturn> func)
        {
            return (a) =>
                      {
                          BeforeInvoke(name);
                          return func(a);
                      };
        }

        public static Action Debug(string name, Action action)
        {
            return () =>
            {
                BeforeInvoke(name);
                action();
            };
        }

        public static Action<T> Debug<T>(string name, Action<T> action)
        {
            return (a1) =>
                      {
                          BeforeInvoke(name);
                          action(a1);
                      };
        }

        public static Action<T1, T2> Debug<T1, T2>(string name, Action<T1, T2> action)
        {
            return (a1, a2) =>
                      {
                          BeforeInvoke(name);
                          action(a1, a2);
                      };
        }

        public static Func<T1, T2, TReturn> Debug<T1, T2, TReturn>(string name, Func<T1, T2, TReturn> func)
        {
            return (a1, a2) =>
                      {
                          BeforeInvoke(name);
                          return func(a1, a2);
                      };
        }
    }
}